class Exploitdb < Formula
  desc "Database of public exploits and corresponding vulnerable software"
  homepage "https://www.exploit-db.com/"
  url "https://github.com/offensive-security/exploitdb.git",
      tag:      "2022-02-11",
      revision: "a6102b7922d958afd4353e10ed6827e3131c5414"
  version "2022-02-11"
  license "GPL-2.0-or-later"
  head "https://github.com/offensive-security/exploitdb.git", branch: "master"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_monterey: "bd94afd7b7df4a5765863192f9035fade330e512c0c71ff0cea9da7434a903bf"
    sha256 cellar: :any_skip_relocation, arm64_big_sur:  "42ad558f23848890afe8138ddb4aded7f3118caf86f10bb8335cc33d2e886904"
    sha256 cellar: :any_skip_relocation, monterey:       "813290162bf4d843ffd97d4ba13771b0d779b2d11138157fceed1e9ff465cccd"
    sha256 cellar: :any_skip_relocation, big_sur:        "3e23c5bdc738d25b8733e315fe85b9a890c22fcbd1cb613674dfbfcab18bc1b5"
    sha256 cellar: :any_skip_relocation, catalina:       "f1a5ad71ca8fd744e154e8b2bbdbb365321ff640ac8f333a6a3d167cf8c8d464"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "5dd3f2f1f8a3c0f1a382774b5881565c5aff5c26243972be9365ae1bc5b73cec"
  end

  def install
    inreplace "searchsploit",
              "rc_file=\"\"", "rc_file=\"#{etc}/searchsploit_rc\""

    optpath = opt_share/"exploitdb"
    inreplace ".searchsploit_rc" do |s|
      s.gsub! "\"/opt/exploitdb\"", optpath
      s.gsub! "\"/opt/exploitdb-papers\"", "#{optpath}-papers"
    end

    bin.install "searchsploit"
    etc.install ".searchsploit_rc" => "searchsploit_rc"

    pkgshare.install %w[.git exploits files_exploits.csv files_shellcodes.csv
                        shellcodes]
  end

  test do
    system "#{bin}/searchsploit", "sendpage"
  end
end
